const dateTime = {}
dateTime.formatDateTime = function (value, count) {
  let date
  if (count !== 3 && count !== 4) {
    date = new Date(value * 1000)
  } else if (count === 3 || count === 4) {
    date = new Date(value)
  }
  let y = date.getFullYear()
  let MM = date.getMonth() + 1
  MM = MM < 10 ? '0' + MM : MM
  let d = date.getDate()
  d = d < 10 ? '0' + d : d
  let h = date.getHours()
  h = h < 10 ? '0' + h : h
  let m = date.getMinutes()
  m = m < 10 ? '0' + m : m
  let s = date.getSeconds()
  s = s < 10 ? '0' + s : s
  if (count === 1) {
    return y + '-' + MM + '-' + d + '　' + h + ':' + m + ':' + s
  } else if (count === 2 || count === 4) {
    return y + '-' + MM + '-' + d
  } else if (count === 3) {
    return y + '年' + MM + '月' + d + '日'
  }
}
dateTime.formatCurrency = function (num) {
  num = num.toString().replace(/\$|,/g, '')
  if (isNaN(num)) num = '0'
  var sign = num == (num = Math.abs(num))
  num = Math.floor(num * 100 + 0.50000000001)
  var cents = num % 100
  num = Math.floor(num / 100).toString()
  if (cents < 10) cents = '0' + cents
  for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3))
  return '￥' + (sign ? '' : '-') + num + '.' + cents
}
export default dateTime
